qui(
    function (require, exports, module) {
        VODCom.Pic = {
            eventManager: VODCom.EventManager(),
            foldStart: -1,
            foldEnd: -1,
            clear: function () {
                this.foldStart = -1;
                this.foldEnd = -1;
                $(".fold_select").removeClass("fold_select");
                console.log("清除收纳信息")
            },
            recordStart: function () {
                if (this.foldStart > 0) {
                    $(".fold_select").removeClass("fold_select");
                }
                this.foldStart = parseInt($(".red").parent().find(".pid").html());
                $(".red").parent().find(".pid").addClass("fold_select");
                if (this.foldEnd < 0) {
                    return;
                }
                this.foldPics(this.foldStart, this.foldEnd);
                $(".fold_select").removeClass("fold_select");
                this.clear();
            },
            recordEnd: function () {
                if (this.foldEnd > 0) {
                    $(".fold_select").removeClass("fold_select");
                }
                this.foldEnd = parseInt($(".red").parent().find(".pid").html());
                $(".red").parent().find(".pid").addClass("fold_select");
                if (this.foldStart < 0) {
                    return;
                }
                this.foldPics(this.foldStart, this.foldEnd);
                $(".fold_select").removeClass("fold_select");
                this.clear();
            },
            //图片收录优化
            foldPics: function (startIndex, endIndex) {
                if (endIndex < startIndex) {
                    var temp = startIndex;
                    startIndex = endIndex;
                    endIndex = temp;
                }
                console.log("图片收录优化")
                var startId = "#img-" + startIndex;
                var endId = "#img-" + endIndex;
                if ($(startId).length > 0 && $(endId).length > 0) {
                    this.eventManager.dispatchEvent({type: "fold_pic", data: [startIndex, endIndex]})
                    for (var imageId = startIndex; imageId <= endIndex; imageId++) {
                        $("#img-" + imageId).parent().hide();
                    }
                    var hiddenArr = $("div[id^=cate]:hidden");
                    var nodeStart = -100;
                    var nodeEnd = -100;
                    var curIndex = 0;
                    var newFold = [];
                    $.each(hiddenArr, function (i, element) {
                        curIndex = parseInt($(element).find("span").html());
                        if (curIndex > nodeEnd + 1) {
                            if (nodeStart >= 0) {
                                newFold.push({ start: nodeStart, end: nodeEnd});
                            }
                            nodeStart = curIndex;
                            nodeEnd = curIndex;
                        } else if (curIndex == nodeEnd + 1) {
                            nodeEnd = curIndex;
                        }
                    })
                    if (nodeEnd >= nodeStart) {
                        newFold.push({ start: nodeStart, end: nodeEnd});
                    }
                    var foldData = $('#makedImg').data("fold");
                    if (foldData == null) {
                        foldData = [];
                    }
                    $.each(foldData, function (i, element) {
                        $("div[fold-key=" + (element.start + "_" + element.end) + "]").remove();
                    })
                    $.each(newFold, function (i, element) {
                        VODCom.Pic.foldDivMakeUp(element);
                    })
                    $('#makedImg').data("fold", newFold);
                }
            },
            foldDivMakeUp: function (element) {
                this.eventManager.dispatchEvent( {type:"fold_makeUp",data:element} )
            },
            extendPics: function (foldSpan) {
                var $foldElement = $(foldSpan).parent();
                var startIndex = parseInt($foldElement.attr("fold-start"));
                var endIndex = parseInt($foldElement.attr("fold-end"));
                var foldData = $('#makedImg').data("fold");
                var newFold = [];
                $.each(foldData, function (i, element) {
                    if (element.start == startIndex && element.end == endIndex) {
                        $foldElement.remove();
                    } else {
                        newFold.push(element);
                    }
                })
                for (var imageId = startIndex; imageId <= endIndex; imageId++) {
                    $("#img-" + imageId).parent().show();
                }
                $('#makedImg').data("fold", newFold);
                this.eventManager.dispatchEvent({type: "extend_pics", data: [startIndex, endIndex]})
            }
        };
        VODCom.Pic.eventManager.bindEvent("change_big_pic",function(){
            $('div[fold-key]').css({
                'width': '280px',
                'height': '220px'
            });
        })
        VODCom.Pic.eventManager.bindEvent("change_small_pic",function(){
            $('div[fold-key]').css({
                'width': '120px',
                'height': '96px'
            });
        })
        VODCom.Pic.eventManager.bindEvent("add_image_mask",function(data){
            console.log("wait to do");
        })
    }
);